import { useContext } from 'react'
import { AuthContext } from '../contexts/AuthContext'

export interface User {
  id: string
  email: string
  name: string
  nickname?: string
  telegram?: string
}

export interface AuthContextType {
  isAuthenticated: boolean
  user: User | null
  login: (email: string, password: string) => Promise<void>
  logout: () => void
  register: (
    email: string,
    password: string,
    name: string,
    verifyCode: string
  ) => Promise<void>
  resetPassword: (email: string) => Promise<void>
}

export function useAuth() {
  const context = useContext(AuthContext)
  if (context === undefined) {
    throw new Error('useAuth must be used within an AuthProvider')
  }
  return context
}